package com.samsungmobile.tellafriend;

import java.util.HashMap;

import com.samsungmobile.common.Conf;
import com.samsungmobile.common.mail.MailSender;
import com.samsungmobile.common.util.EasyFile;
import com.samsungmobile.common.util.EasyString;

public class SendMail{

   	//Replace for mail templete
	private final String sfREPLACE_SENDER_NAME = "###SENDER_NAME###";
	private final String sfREPLACE_SENDER_EMAIL = "###SENDER_EMAIL###"; 
	private final String sfREPLACE_RECEIVER_NAME = "###RECEIVER_NAME###"; 
	private final String sfREPLACE_RECEIVER_EMAIL = "###RECEIVER_EMAIL###"; 
	private final String sfREPLACE_MESSAGE = "###MESSAGE###"; 
	private final String sfURL_ROOT = "###URL_ROOT###"; 
	
    public void SendMail(HashMap hm) throws Exception{
    	
    	String sTitle = (String)hm.get("TITLE");
    	String sSender_name = (String)hm.get("SENDER_NAME");
    	String sSender_email = (String)hm.get("SENDER_EMAIL");
    	String sReceiver_name = (String)hm.get("RECEIVER_NAME");
    	String sReceiver_email = (String)hm.get("RECEIVER_EMAIL");
    	String sMessage = (String)hm.get("MESSAGE");
    	String sLang_cd = (String)hm.get("LANG_CD");
    	
    	String sMail_templete = "";
    	String sUrl_root = new Conf().getConf("url_root");
    	StringBuffer sbPath_file = new StringBuffer();
    	
    	sbPath_file.append("/home01/sm3/webapps/promo/prm/ea/mail_templete/");
    	sbPath_file.append(sLang_cd);
    	sbPath_file.append("_");
    	sbPath_file.append("tellafriend.jsp");

        sMail_templete = EasyFile.readFile(sbPath_file.toString());

        sMail_templete = EasyString.replace(sMail_templete, sfREPLACE_SENDER_NAME, sSender_name);
        sMail_templete = EasyString.replace(sMail_templete, sfREPLACE_SENDER_EMAIL, sSender_email);
        sMail_templete = EasyString.replace(sMail_templete, sfREPLACE_RECEIVER_NAME, sReceiver_name);
        sMail_templete = EasyString.replace(sMail_templete, sfREPLACE_RECEIVER_EMAIL, sReceiver_email);
        sMail_templete = EasyString.replace(sMail_templete, sfREPLACE_MESSAGE, sMessage);
        sMail_templete = EasyString.replace(sMail_templete, sfURL_ROOT, sUrl_root);

    	MailSender.send("tellafriend@samsungmobile.com", sReceiver_email, sTitle, sMail_templete);
 
    }
}